home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_03 / grant / pop.h < prev    next >
C/C++ Source or Header  |  1994-12-22  |  1KB  |  52 lines

  1. #include "random.h"
  2. #include "chrom.h"
  3.  
  4. #ifndef _INC_POP_
  5. #define _INC_POP_
  6.  
  7. class CGAPopulation
  8. {
  9. public:
  10.   ~CGAPopulation();
  11.    CGAPopulation(size_t Size, size_t Length,
  12.                  float MaxMutationRate);
  13.  
  14.    void          CreateNextGeneration(void);
  15.    inline float  GetBestFitness(void);
  16.    inline size_t GetGeneration(void);
  17.    inline size_t GetPopulationSize(void);
  18.    inline CGAChromosome* GetChromosome(size_t Idx);
  19.    
  20. private:
  21.    CGAChromosome* GetParent();
  22.  
  23.    void ReplaceChromosome(CGAChromosome* Chromosome);
  24.    void Merge(CGAChromosome* NewChromosome);
  25.    
  26.    size_t          m_MaxSize;
  27.    size_t          m_CurrentSize;
  28.    CGAChromosome** m_Data;
  29.    size_t          m_Generation;
  30.    float           m_MaxMutationRate;
  31. };
  32.  
  33. float CGAPopulation::GetBestFitness(void) {
  34.    return m_Data[0]->GetFitness();
  35. }
  36.  
  37. size_t CGAPopulation::GetGeneration(void) {
  38.    return m_Generation;
  39. }
  40.  
  41. size_t CGAPopulation::GetPopulationSize(void) {
  42.    return m_CurrentSize; 
  43. }
  44.  
  45. CGAChromosome* CGAPopulation::GetChromosome(
  46.    size_t Idx)
  47. {
  48.    return m_Data[Idx];
  49. }
  50.  
  51. #endif
  52.